package com.andrew.demo.mapper;

import com.andrew.demo.model.BaseDbEntity;

import java.util.Map;

public class MapperHelper {

    public static Map<String, BaseMapper> mapperMap;


    public  void MapperHelper()
    {
        mapperMap.put("userMapper", new UserMapper());
        mapperMap.put("studentMapper",new StudentMapper());
    }

    public static BaseMapper getRowMapperByClass( String name) throws ClassNotFoundException, IllegalAccessException, InstantiationException {

        // 1. 传入 User  我们要返回 UserMapper
        // 2. T的ClassName直接加Mapper
        // 3. 后期优化可特例Map配置


//        T.newInstance.getClass()
        //方案一
        String className="User";
        //加载一个用户实体类UserBean
        Class mapperCls = Class.forName("com.andrew.demo.mapper."+className+"Mapper");
        //return (BaseMapper) mapperCls.newInstance();

        //baseDbEntityCls.getSimpleName();

        //方案二
        BaseMapper baseMapper= mapperMap.get("studentMapper");
        return baseMapper;
    }
}
